<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="test"></div>

  <script src="./js/react.development.js"></script>
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/babel.min.js"></script>
  <!-- 引入prop-types，用于对组件标签属性进行限制 -->
  <script type="text/javascript" src="./js/prop-types.js"></script>
  <script type="text/babel">
    class Login extends React.Component {
      state = { name: '', pwd: '' }

      changeData = (dataType) => {
        return (event) => {
          this.setState({ [dataType]: event.target.value })
        }
      }

      subFn = (event) => {
        event.preventDefault()
        console.log(this.state)
      }

      render() {
        return (
          <div>
            <form onSubmit={this.subFn}>
              <input type="text" onChange={this.changeData('name')} />
              <input type="text" onChange={this.changeData('pwd')} />
              <button>btn</button>
            </form>
          </div>
        )
      }
    }

    ReactDOM.render(<Login />, document.getElementById('test'))
  </script>

</body>

</html>